/*
 * Brisk
 *
 * Cross-platform application framework
 * --------------------------------------------------------------
 *
 * Copyright (C) 2025 Brisk Developers
 *
 * This file is part of the Brisk library.
 *
 * Brisk is dual-licensed under the GNU General Public License, version 2 (GPL-2.0+),
 * and a commercial license. You may use, modify, and distribute this software under
 * the terms of the GPL-2.0+ license if you comply with its conditions.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 *
 * If you do not wish to be bound by the GPL-2.0+ license, you must purchase a commercial
 * license. For commercial licensing options, please visit: https://brisklib.com
 */
#pragma once

#include <vector>
#include <algorithm>
#include <iterator>

namespace Brisk {

/**
 * @brief Generates a vector by applying a functor a specified number of times.
 *
 * This function creates a vector of a given size and fills it with values
 * generated by invoking the provided functor.
 *
 * @tparam Functor The type of the functor used for generating values.
 * @param count The number of elements to generate.
 * @param functor The functor that produces the values.
 * @return A vector containing the generated values.
 */
template <typename Functor>
inline auto generate(size_t count, Functor functor) -> std::vector<decltype(functor())> {
    std::vector<decltype(functor())> result(count);
    std::generate(result.begin(), result.end(), functor);
    return result;
}

/**
 * @brief Transforms the elements of a vector using a functor.
 *
 * This function applies the provided functor to each element of the input vector
 * and returns a new vector containing the transformed values.
 *
 * @tparam ValueType The type of the elements in the input vector.
 * @tparam Alloc The allocator type used by the input vector.
 * @tparam Functor The type of the functor used for transformation.
 * @param container The input vector to transform.
 * @param functor The functor to apply to each element of the vector.
 * @return A vector containing the transformed values.
 */
template <typename ValueType, typename Alloc, typename Functor>
inline auto map(const std::vector<ValueType, Alloc>& container, Functor&& functor)
    -> std::vector<decltype(functor(std::declval<ValueType>()))> {
    std::vector<decltype(functor(std::declval<ValueType>()))> result;
    std::transform(container.begin(), container.end(), std::back_inserter(result), functor);
    return result;
}

} // namespace Brisk
